package echat.future.cn.echat.message.rank.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.message.rank.bean.RankBean;
import echat.future.cn.echat.my.weight.CircleImageView;

/**
 * Created by JX on 2018/8/19.
 */

public class RankAdapter extends BaseQuickAdapter<RankBean, BaseViewHolder> {

    private int type;

    public RankAdapter(int layoutResId, @Nullable List<RankBean> data, int type) {
        super(layoutResId, data);
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, RankBean item) {
        helper.setText(R.id.tv_position, "NO." + (helper.getLayoutPosition() + 4));

        RequestOptions options = new RequestOptions();
        options.centerCrop()
                .placeholder(R.mipmap.ic_launcher);
        Glide.with(mContext).load(item.getUser_avatar()).apply(options).into((CircleImageView) helper.getView(R.id.iv_head));

        helper.setText(R.id.tv_name, item.getUsername());

        helper.setText(R.id.tv_num, item.getNum());

        helper.setGone(R.id.tv_type, type == 1 ? true : false);
        helper.setImageResource(R.id.iv_icon, type == 1 ? R.drawable.zhuanshi : R.drawable.ph_jinbi);

        helper.setGone(R.id.tv_jibie, type == 1 ? false : true);

        helper.setText(R.id.tv_jibie, "LV." + item.getLevel());

        helper.setGone(R.id.iv_rz, item.getUser_role() == 2 ? true : false);

        if (TextUtils.isEmpty(item.getGj())) {
            helper.setGone(R.id.iv_gj, false);
        } else {
            helper.setGone(R.id.iv_gj, true);

            if (item.getGj().equals("cg")) {
                helper.setImageResource(R.id.iv_gj, R.drawable.btn_guan_cai);
            } else if (item.getGj().equals("jg")) {
                helper.setImageResource(R.id.iv_gj, R.drawable.btn_guan_huang);
            } else {
                helper.setImageResource(R.id.iv_gj, R.drawable.btn_guan_yin);
            }
        }
    }
}
